package cn._2dland.uploader.utils
{
	public final class TaskUtils
	{
		public function TaskUtils() {}

		private static function getStringLength(str:String):uint{
			var len:uint = 0;
			for(var i:int=0; i<str.length; i++){
				var cc:Number = str.charCodeAt(i);
				if(cc <= 127) len += 1;
				else len += 2;
			}
			return len;
		}

		public static function processTitle(title:String):String {
			var t:String = title;
			while(getStringLength(t) > 40){
				t = t.substring(0, t.length-1);
			}
			return t;
		}

		public static function processTags(tags:String):String {
			var tagArray:Array = tags.split(" ");
			for(var i:int=0; i<tagArray.length; i++){
				var tag:String = String(tagArray[i]);
				if(tag.length <= 8) continue;
				tag = tag.substr(0, 8);
				tagArray[i] = tag;
			}
			return tagArray.join(" ");
		}
	}
}